package com.shunhao.utils

import android.app.Activity
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.gyf.immersionbar.ImmersionBar

/**
 * @author
 * @date 2019/8/15
 * @ddescription 透明状态栏设置状态栏颜色工具类
 */
object ImmersionBarUtils {

    /**
     * 初始化白色Dialog状态栏
     *
     * @param dialogFragment dialogFragment
     */
    fun initWhiteDialogTransBar(dialogFragment: DialogFragment) {
        ImmersionBar.with(dialogFragment)
            .keyboardEnable(true)
            .fullScreen(false)
            .statusBarColor(R.color.white)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .fitsSystemWindows(true)
            .autoDarkModeEnable(true)
            .navigationBarColor(R.color.white)
            .init()
    }

    /**
     * 首页轮播图
     *
     * @param fragment fragment
     */
    fun initTranslBarHome(fragment: Fragment, view: Int) {
        ImmersionBar.with(fragment)
            .fullScreen(true)
            .transparentStatusBar()
            .statusBarView(view)
            .transparentBar()
            .barAlpha(0.0f)
            .statusBarColor(R.color.transparent)
            .fitsSystemWindows(false)
            .autoDarkModeEnable(true)
            .init()
    }

    /**
     * 初始化基础白色状态栏
     *
     * @param activity activity
     */
    @JvmStatic
    fun initBaseBar(activity: Activity) {
        ImmersionBar.with(activity) //.keyboardEnable(true)
            .fitsSystemWindows(true)
            .fullScreen(false)
            .statusBarColor(R.color.white)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .autoDarkModeEnable(true)
            .navigationBarColor(R.color.white)
            .init()
    }

    @JvmStatic
    fun initColorBaseBar(activity: Activity, color: Int) {
        ImmersionBar.with(activity) //.keyboardEnable(true)
            .fitsSystemWindows(true)
            .fullScreen(false)
            .statusBarColor(color)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .autoDarkModeEnable(true)
            .navigationBarColor(color)
            .init()
    }


    fun initColorBaseBar(fragment: Fragment, statusBarColor: Int) {
        ImmersionBar.with(fragment) //.keyboardEnable(true)
            .fullScreen(false)
            .statusBarColor(statusBarColor)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .fitsSystemWindows(true) //.autoDarkModeEnable(true)
            .navigationBarColor(R.color.white)
            .init()
    }


    /**
     * @date 2019-10-11 16:05
     * @description 色值
     */
    @JvmStatic
    fun initColorBar(activity: Activity, color: Int) {
        ImmersionBar.with(activity) //.keyboardEnable(true)
            .fullScreen(false) //.transparentStatusBar()
            .statusBarColor(color)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .fitsSystemWindows(true)
            .autoDarkModeEnable(true)
            .navigationBarColor(R.color.white)
            .init()
    }

    /**
     * 状态栏导航栏同时隐藏
     *
     * @param activity activity
     */
    fun initHideBar(activity: Activity) {
        ImmersionBar.with(activity)
            .keyboardEnable(true)
            .fullScreen(true)
            .transparentStatusBar()
            .navigationBarColor(R.color.transparent)
            .fitsSystemWindows(false)
            .init()
    }

    fun initBlackTheme(activity: Activity) {
        ImmersionBar.with(activity) //.keyboardEnable(true)
            .fullScreen(false) //.transparentStatusBar()
            .statusBarColor(R.color.black)
            .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
            .fitsSystemWindows(true)
            .autoDarkModeEnable(true)
            .navigationBarColor(R.color.black)
            .init()
    }

    /**
     * 释放重置
     *
     * @param fragment fragment
     */
    fun reset(fragment: Fragment) {
        ImmersionBar.with(fragment).reset()
    }

    /**
     * 释放重置
     *
     * @param activity activity
     */
    fun reset(activity: Activity) {
        ImmersionBar.with(activity).reset()
    }
}